import Vue from 'vue'
import App from './App.vue'
import store from './store/index'
import router from './router/index'
import './plugins/elementUI'
import './assets/css/global.scss'
import API from './api/axios'
import MyUI from '@/components/index'
import VueParticles from 'vue-particles'
import Cookies from 'js-cookie'
import VueClipboard from 'vue-clipboard2'
import './router/permission'

// 自定义插件（全局引入公共组件）
Vue.use(MyUI)
Vue.prototype.$API = API
Vue.use(VueParticles)
Vue.use(VueClipboard)
Vue.prototype.$Cookies = Cookies

Vue.config.productionTip = false

// 注册全局自定义指令：按钮级别权限控制
Vue.directive('perms', {
  inserted: (el, binding, vnode) => {
    let permission = binding.value
    if (permission) {
      let hasPerm = vnode.context.$store.getters.perms.some(item => {
        return item.perms === permission
      })
      if (!hasPerm) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    }
  }
})

new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')
